package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.UsersCoupon;
import com.ytjj.qmyx.admin.model.request.UsersCouponRelationRequest;
import com.ytjj.qmyx.admin.model.request.UsersCouponRequest;
import com.ytjj.qmyx.admin.service.UsersCouponService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/usersCoupon")
public class UsersCouponController {

    @Resource
    private UsersCouponService usersCouponService;

    /**
     * 获取用户优惠券列表
     * @param usersCouponRequest
     * @return
     */
    @PostMapping("/getUsersCouponList")
    @OperLog(operModule = "优惠券模块", operDesc = "后台发放优惠券", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult getUsersCouponList(@RequestBody UsersCouponRequest usersCouponRequest){
        CommonPage<UsersCoupon> pageList = usersCouponService.getList(usersCouponRequest);
        return CommonResult.success(pageList);
    }

    /**
     * 给用户发放优惠券
     * @param ucrRelation
     * @return
     */
    @PostMapping("/insertRelation")
    @OperLog(operModule = "优惠券模块", operDesc = "后台发放优惠券", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult insertRelation(@RequestBody UsersCouponRelationRequest ucrRelation){
        int count = usersCouponService.insertRelation(ucrRelation);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
